package com.niit.serializtion;

import org.apache.hadoop.io.Writable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class student implements Writable {
    private  int id;
    private  String name;
    private  String sex;
    private  int age;
    private  String address;

    //空构造器，  构造函数：当被实例化的时候就会调用方法
    public student(){
    }
    //有参构造函数
    public student(int id, String name, String sex, int age, String address) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.address = address;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }



    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", address='" + address + '\'' +
                '}';
    }

    //序列化方法
    @Override
    public  void write(DataOutput out) throws IOException{
        out.writeInt(id);
        out.writeUTF(name);
        out.writeUTF(sex);
        out.writeInt(age);
        out.writeUTF(address);

    }


    //反序列化方法,顺序一样；
    @Override
    public void readFields(DataInput in) throws IOException{
        this.id =in.readInt();
        this.name =in.readUTF();
        this.sex =in.readUTF();
        this.age =in.readInt();
        this.address =in.readUTF();


    }
}
